package com.sc.nft.admin.controller;


import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.CollectionChipCreateDTO;
import com.sc.nft.dto.CollectionChipReceiveDTO;
import com.sc.nft.entity.dto.CollectionChipDTO;
import com.sc.nft.entity.dto.CollectionChipIdDTO;
import com.sc.nft.entity.vo.CollectionChipDetailsVO;
import com.sc.nft.entity.vo.CollectionChipReceivePageVO;
import com.sc.nft.entity.vo.CollectionChipVO;
import com.sc.nft.service.CollectionChipService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/collection/chip")
@Api(tags = "芯片程序")
public class CollectionChipController {
    private final CollectionChipService collectionChipService;

    @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加芯片程序", notes = "添加芯片程序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result create(@Valid @RequestBody CollectionChipCreateDTO collectionChipDTO) {
        collectionChipService.create(collectionChipDTO);
        return Result.success();
    }

    @PostMapping(value = "/receive/record", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "领取记录", notes = "领取记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<CollectionChipReceivePageVO> receiveRecord(@Valid @RequestBody CollectionChipReceiveDTO receiveDTO) {
        return PageResult.success(collectionChipService.receiveRecord(receiveDTO));
    }


    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "后台芯片程序列表", notes = "后台芯片程序列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<CollectionChipVO> getAdminCollectionChipPage(@Valid @RequestBody CollectionChipDTO collectionChipDTO) {
        return PageResult.success(collectionChipService.getAdminCollectionChipPage(collectionChipDTO));
    }


    @PostMapping(value = "/details", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "芯片 详情", notes = "芯片 详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<CollectionChipDetailsVO> getCollectionChipDetails(@Valid @RequestBody CollectionChipIdDTO collectionChipIdDTO) {
        return PageResult.success(collectionChipService.getCollectionChipDetails(collectionChipIdDTO.getId()));
    }
}
